<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="http://xmlns.heustics.org/schema/myelin/0.1/" 
  xmlns:o="&a;options#"
  exclude-result-prefixes="xsl a l o"
>  
  <xsl:template match="a:option" mode="a:single-select">
    <xsl:param name="l10n"/>
    <xsl:param name="selected"/>  
    <xsl:param name="value" select="@key"/>      
    <option value='{$value}'>
      <xsl:if test='$selected = $value'>
        <xsl:attribute name='selected'>selected</xsl:attribute>
      </xsl:if>      
      <xsl:value-of select='$l10n[@key=$value]'/>
    </option>
  </xsl:template> 
  
  <xsl:template match="a:option" mode="a:single-select-label">    
    <xsl:param name="selected"/>  
    <xsl:param name="value" select="@key"/>      
    <option value='{$value}'>
      <xsl:if test='$selected = $value'>
        <xsl:attribute name='selected'>selected</xsl:attribute>
      </xsl:if>      
      <xsl:value-of select='@label'/>
    </option>
  </xsl:template> 
  
  <!-- selections -->
  <xsl:template match="a:options" mode="a:multiple-selection">
    <xsl:param name="name"/>
    <xsl:param name="selection"/>
    <xsl:param name="header"/>
    <xsl:param name="l10n"/>
    <div class="input_header">
      <span>
        <xsl:value-of select="$header"/>
      </span>
      <div class="spacer"/>
    </div>
    <div class="multiple_selection">      
      <xsl:apply-templates select="*" mode="a:option">
        <xsl:with-param name="l10n" select="$l10n"/>
        <xsl:with-param name="name" select="$name"/>
        <xsl:with-param name="selection" select="$selection"/>
      </xsl:apply-templates>   
      <div class="spacer"/>           
    </div>   
  </xsl:template> 
  
  <xsl:template match="a:option" mode="a:option">
    <xsl:param name="name"/>
    <xsl:param name="selection"/>
    <xsl:param name="l10n"/>
    <xsl:param name="key" select="@key"/>
    <xsl:param name="display-text" select="$l10n[@key=$key]"/>
    <div class="entry option"> 
      <input type="checkbox" name="{$name}" value="{$key}">
        <xsl:if test="$selection[@key=$key]">
          <xsl:attribute name="checked">checked</xsl:attribute>
        </xsl:if>             
      </input>
      <span>
        <xsl:value-of select="$display-text"/>
      </span>
      <div class="spacer"/> 
    </div>
  </xsl:template>
  
  <xsl:template match="a:optgroup" mode="a:option">
    <xsl:param name="selection"/>
    <xsl:param name="l10n"/>
    <xsl:param name="name" select="@name"/>
    <xsl:param name="optgroup-l10n" select="$l10n/l:context[@name=$name]/*"/>
    <xsl:param name="header" select="$optgroup-l10n[@key='header']"/>
    <div class="entry optgroup">  
      <div class="input_header">
        <span>
          <xsl:value-of select="$header"/>
        </span>
        <div class="spacer"/>
      </div>               
      <xsl:apply-templates mode="a:optgroup">
        <xsl:with-param name="l10n" select="$optgroup-l10n"/>
        <xsl:with-param name="selection" select="$selection"/>
        <xsl:with-param name="optgroup" select="@name"/>
      </xsl:apply-templates>
      <div class="spacer"/> 
    </div>
  </xsl:template>
  
  <xsl:template match="a:option" mode="a:optgroup">
    <xsl:param name="selection"/>
    <xsl:param name="l10n"/>
    <xsl:param name="optgroup"/>
    <xsl:param name="key" select="@key"/>
    <xsl:param name="display-text" select="$l10n[@key=$key]"/>
    <div class="option">            
      <xsl:variable name="sel-key" select="concat($optgroup,' ',@key)"/>
      <input type="checkbox" name="type" value="{$key}">
        <xsl:if test="$selection[@key=$sel-key]">
          <xsl:attribute name="checked">checked</xsl:attribute>
        </xsl:if>             
      </input>
      <span>
        <xsl:value-of select="$display-text"/>
      </span>
      <div class="spacer"/> 
    </div>
  </xsl:template> 
    
  <xsl:template match="*" mode="a:radio-select-by-position">
    <xsl:param name="name"/>
    <xsl:param name="selected"/>
    <div class="radio_select">
      <xsl:variable name="p" select="position()-1"/>
      <input type="radio" name="{$name}" value="{$p}">
        <xsl:if test="number($selected) = $p">
          <xsl:attribute name="checked">checked</xsl:attribute>
        </xsl:if>
      </input>        
      <span><xsl:value-of select="."/></span>
      <div class="spacer"/>     
    </div>
  </xsl:template>

</xsl:stylesheet>
